<template>
  <a-drawer
    :title="title"
    :width="width"
    placement="right"
    :closable="false"
    @close="close"
    :visible="visible">
  
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item label="姓名" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['name']" placeholder="请输入姓名"></a-input>
        </a-form-item>
        <a-form-item label="性别" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['sex']" placeholder="请输入性别" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="出生日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['borth']" placeholder="请输入出生日期"></a-input>
        </a-form-item>
        <a-form-item label="联系电话" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['phone']" placeholder="请输入联系电话"></a-input>
        </a-form-item>
        <a-form-item label="民族" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['mzcode']" placeholder="请输入民族"></a-input>
        </a-form-item>
        <a-form-item label="政治面貌" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['zzmm']" placeholder="请输入政治面貌"></a-input>
        </a-form-item>
        <a-form-item label="身份证号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['sfzh']" placeholder="请输入身份证号"></a-input>
        </a-form-item>
        <a-form-item label="学历" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['xl']" placeholder="请输入学历"></a-input>
        </a-form-item>
        <a-form-item label="户籍所在地" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['hjdz']" placeholder="请输入户籍所在地"></a-input>
        </a-form-item>
        <a-form-item label="家庭住址" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['jtdz']" placeholder="请输入家庭住址"></a-input>
        </a-form-item>
        <a-form-item label="单位" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['dwname']" placeholder="请输入单位"></a-input>
        </a-form-item>
        <a-form-item label="部门" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['bmname']" placeholder="请输入部门"></a-input>
        </a-form-item>
        <a-form-item label="岗位" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['gwname']" placeholder="请输入岗位"></a-input>
        </a-form-item>
        <a-form-item label="职务或工种" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['zwgz']" placeholder="请输入职务或工种"></a-input>
        </a-form-item>
        <a-form-item label="职称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['zc']" placeholder="请输入职称"></a-input>
        </a-form-item>
        <a-form-item label="入职时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['rzdate']" placeholder="请输入入职时间"></a-input>
        </a-form-item>
        <a-form-item label="合同类别" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['htlb']" placeholder="请输入合同类别"></a-input>
        </a-form-item>
        <a-form-item label="岗位类别" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['gwlb']" placeholder="请输入岗位类别"></a-input>
        </a-form-item>
        <a-form-item label="岗位运行方式" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['gzfs']" placeholder="请输入岗位运行方式"></a-input>
        </a-form-item>
        <a-form-item label="合同起始日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['htstdt']" placeholder="请输入合同起始日期"></a-input>
        </a-form-item>
        <a-form-item label="合同终止日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['htenddt']" placeholder="请输入合同终止日期"></a-input>
        </a-form-item>
        <a-form-item label="合同有效日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['htyxrq']" placeholder="请输入合同有效日期"></a-input>
        </a-form-item>
        <a-form-item label="用工来源" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['ygly']" placeholder="请输入用工来源"></a-input>
        </a-form-item>
        <a-form-item label="开资账号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['kzzh']" placeholder="请输入开资账号"></a-input>
        </a-form-item>
        <a-form-item label="安全奖" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['aqj']" placeholder="请输入安全奖"></a-input>
        </a-form-item>
        <a-form-item label="月工资" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['ygz']" placeholder="请输入月工资"></a-input>
        </a-form-item>
        <a-form-item label="奖金系数" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['jjxs']" placeholder="请输入奖金系数"></a-input>
        </a-form-item>
        <a-form-item label="浮动工资" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['fdgz']" placeholder="请输入浮动工资"></a-input>
        </a-form-item>
        <a-form-item label="代缴" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['dj']" placeholder="请输入代缴"></a-input>
        </a-form-item>
        <a-form-item label="岗位津贴" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['gwjt']" placeholder="请输入岗位津贴"></a-input>
        </a-form-item>
        <a-form-item label="备注1" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['remark1']" placeholder="请输入备注1"></a-input>
        </a-form-item>
        <a-form-item label="备注2" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['remark2']" placeholder="请输入备注2"></a-input>
        </a-form-item>
        <a-form-item label="是否备案" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['isba']" placeholder="请输入是否备案" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="原因" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['reason']" placeholder="请输入原因"></a-input>
        </a-form-item>
        <a-form-item label="创建人" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['createBy']" placeholder="请输入创建人"></a-input>
        </a-form-item>
        <a-form-item label="创建日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择创建日期" v-decorator="['createTime']" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="更新人" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['updateBy']" placeholder="请输入更新人"></a-input>
        </a-form-item>
        <a-form-item label="更新日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择更新日期" v-decorator="['updateTime']" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        
      </a-form>
    </a-spin>
    <a-button type="primary" @click="handleOk">确定</a-button>
    <a-button type="primary" @click="handleCancel">取消</a-button>
  </a-drawer>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'
  import JDate from '@/components/jeecg/JDate'  
  
  export default {
    name: "BjYgruzhiModal",
    components: { 
      JDate,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/bj/bjYgruzhi/add",
          edit: "/bj/bjYgruzhi/edit",
        }
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'name','sex','borth','phone','mzcode','zzmm','sfzh','xl','hjdz','jtdz','dwname','bmname','gwname','zwgz','zc','rzdate','htlb','gwlb','gzfs','htstdt','htenddt','htyxrq','ygly','kzzh','aqj','ygz','jjxs','fdgz','dj','gwjt','remark1','remark2','isba','reason','createBy','createTime','updateBy','updateTime'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'name','sex','borth','phone','mzcode','zzmm','sfzh','xl','hjdz','jtdz','dwname','bmname','gwname','zwgz','zc','rzdate','htlb','gwlb','gzfs','htstdt','htenddt','htyxrq','ygly','kzzh','aqj','ygz','jjxs','fdgz','dj','gwjt','remark1','remark2','isba','reason','createBy','createTime','updateBy','updateTime'))
      }
      
    }
  }
</script>

<style lang="less" scoped>
/** Button按钮间距 */
  .ant-btn {
    margin-left: 30px;
    margin-bottom: 30px;
    float: right;
  }
</style>